
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author BENSON
 */
public class ControllerListFlight {
      Connection conn=null;
    String deleteStudent;
    String querry;
    Statement st=null;
   public ListFlights listFlt;
    
    private ActionListener actionListener;
    
    public ControllerListFlight( ){
        listFlt = new ListFlights();
        listFlt.setVisible(true);
                          
    }
   
     
    public void showOrders(){
    try{
        Class.forName("com.mysql.jdbc.Driver");
        conn =(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/jetwingdb?zeroDateTimeBehavior=convertToNull","root","");
        querry="SELECT * FROM Flights ;" ;
        st=conn.prepareStatement(querry);
        st.execute("USE jetwingdb;");

        ResultSet rs= st.executeQuery(querry);
   while(rs.next()){
  
   Object[] temp = {rs.getString("fName"), rs.getString("fFrom"),rs.getString("destination"),rs.getString("price"),
                    rs.getString("fCapacity"),rs.getString("depatureTime"),rs.getString("arrivalTime")};
   listFlt.getTable().addRow(temp);
   }
   st.close();
   conn.close();
  
    }  
    catch(Exception e){
    JOptionPane.showMessageDialog(null,e);
    }
    
    }
     public void contol(){        
        actionListener = new ActionListener() {
              public void actionPerformed(ActionEvent actionEvent) {  
                  if(actionEvent.getSource()==listFlt.getListButton()){
                        showOrders();
                  }
                  if(actionEvent.getSource()==listFlt.getCloseButton()){
                  listFlt.setVisible(false);
                  
                  }
              }
              
        };                
        listFlt.getListButton().addActionListener(actionListener);
        listFlt.getCloseButton().addActionListener(actionListener);
    }   
}
